package org.apache.lucene.index;

import java.io.IOException;
import java.util.Arrays;

import org.apache.lucene.store.IndexInput;

public class TagBlockSkipListReader extends MultiLevelSkipListReader {
  private long[] pointers;

  private long lastPointer;

  public TagBlockSkipListReader(IndexInput skipStream, int maxSkipLevels, int skipInterval) {
    super(skipStream, maxSkipLevels, skipInterval);
    pointers = new long[maxSkipLevels];
  }

  public void init(long skipPointer, long basePointer, int df) {
    super.init(skipPointer, df);
    lastPointer = basePointer;
    Arrays.fill(pointers, basePointer);
  }

  public long getPointer() {
    return lastPointer;
  }

  protected void seekChild(int level) throws IOException {
    super.seekChild(level);
    pointers[level] = lastPointer;
  }

  protected void setLastSkipData(int level) {
    super.setLastSkipData(level);
    lastPointer = pointers[level];
  }

  protected int readSkipData(int level, IndexInput skipStream) throws IOException {
    int delta = skipStream.readVInt();
    pointers[level] += skipStream.readVInt();
    return delta;
  }
}
